package com.gitee.wsl.model.process

import com.gitee.wsl.model.OutgoingContent
import com.gitee.wsl.model.plugin.ModelPluginBuilder
import com.gitee.wsl.model.plugin.ModelPluginInstance
import com.gitee.wsl.prop.AttributeKey

open class ProcessModelPluginBuilder<PluginConfig>(
    key: AttributeKey<ModelPluginInstance<ProcessModel, PluginConfig,ProcessModelPluginBuilder<PluginConfig>>>,
    client: ProcessModel,
    pluginConfig: PluginConfig
): ModelPluginBuilder<ProcessModel, PluginConfig,ProcessModelPluginBuilder<PluginConfig>>(key, client, pluginConfig) {

    /**
     * Specifies the [block] handler for every HTTP request.
     *
     * This block is invoked for every [HttpClient.request] call.
     * There you can modify the request in a way you want: add headers, configure logging, etc.
     *
     * @see [createClientPlugin]
     *
     * @param block An action that needs to be executed when a client creates an HTTP request.
     */
    fun onRequest(block: RequestHookBlock) {
        on(RequestHook, block)
    }

    /**
     * Specifies the [block] handler for every HTTP response.
     *
     * This block is invoked for every incoming response.
     * There you can inspect the response in a way you want: save cookies, add logging, etc.
     *
     * @see [createClientPlugin]
     *
     * @param block An action that needs to be executed when a client receives an HTTP response.
     */
    fun onResponse(block: ResponseHookBlock) {
        on(ResponseHook, block)
    }

    /**
     * Specifies the [block] transformer for a request body.
     *
     * This block is invoked for every [HttpClient.request] call.
     * Here you should serialize body into [OutgoingContent] or return `null` if your transformation is not applicable.
     *
     * @see [createClientPlugin]
     *
     * @param block A transformation of request body.
     */
    fun transformRequestBody(block: TransformRequestBodyHookBlock) {
        on(TransformRequestBodyHook, block)
    }

    /**
     * Specifies the [block] transformer for a response body.
     *
     * This block is invoked for every [HttpResponse.body] call.
     * Here you should deserialize body into an instance of [requestedType]
     * or return `null` if your transformation is not applicable.
     *
     * @see [createClientPlugin]
     *
     * @param block A transformation of response body.
     */
    /*fun transformResponseBody(
       block: suspend TransformResponseBodyContext.(
           response: HttpResponse,
           content: ByteReadChannel,
           requestedType: TypeInfo
       ) -> Any?
   ) {
       on(TransformResponseBodyHook, block)
   }*/

}